function insertSort(arr) {
    var temp;
    for (let i = 1; i < array.length; i++) {
        temp = array[i];
        var j = i;
        while (j > 0 && array[j - 1] > temp) {
            array[j] = array[j - 1];
            j--;
        }
        array[j] = temp;
    }
    return array;
}

// 4 2 1 3
// 2 4 1 3  2443 1243

var containsNearbyAlmostDuplicate = function(nums, k, t) {
    let n = nums.length , r = false;
    if (n === 0) return r;
    for (let i = 0; i < n; i++) {
        let j = i + 1;
        while(Math.abs(i - j) <= k) {
            if (Math.abs(nums[i] - nums[j]) <= t) r = true;
            j++;
        }
    }
    return r;
};
let nums = [1,2,3,1], k = 3, t = 0;
containsNearbyAlmostDuplicate(nums, k, t);